package com.gjs.cd.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gjs.cd.pojo.dto.CdCodeValidTermReq;
import com.gjs.cd.pojo.entity.CdCodeValidTerm;
import com.gjs.cd.service.ICdCodeValidTermService;
import com.gjs.common.manager.response.RspBody;
import com.gjs.common.pojo.dto.request.PageQuery;
import com.gjs.common.pojo.dto.response.ListPageRsp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhongwenguang
 * @date 2022-3-10 18:10
 */

@RestController
@Slf4j
@Api(tags = "年度管理")
@RequestMapping("/cyear")
@RequiredArgsConstructor
public class CdCodeValidTermController {


    private final ICdCodeValidTermService iCdCodeValidTermService;

    @ApiOperation("新增年度")
    @PostMapping("/add")
    public RspBody<Boolean> add(@RequestBody CdCodeValidTermReq cdCodeValidTermReq){
        return RspBody.success(iCdCodeValidTermService.addTerm(cdCodeValidTermReq));
    }

    @ApiOperation("更新")
    @PostMapping("/update")
    public RspBody<Boolean> update(@RequestBody CdCodeValidTermReq cdCodeValidTermReq){
        return RspBody.success(iCdCodeValidTermService.updateTerm(cdCodeValidTermReq));
    }

    @ApiOperation("查询")
    @GetMapping("/list")
    public RspBody<ListPageRsp<CdCodeValidTerm>> list(PageQuery pageQuery,CdCodeValidTermReq cdCodeValidTermReq){
        IPage<CdCodeValidTerm> cdCodeValidTermIPage = iCdCodeValidTermService.page(pageQuery.buildPage(),iCdCodeValidTermService.buildWrapper(cdCodeValidTermReq));
        return RspBody.success(ListPageRsp.of(cdCodeValidTermIPage,CdCodeValidTerm.class));
    }

    @ApiOperation("获取年份")
    @GetMapping("/get_year")
    public RspBody<List<CdCodeValidTerm>> getYear(){
        return RspBody.success(iCdCodeValidTermService.getListYear());
    }
}
